<?php
namespace app\common\service;

use app\common\model\School as SchoolModel;
use think\Db;
use http\Http;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2025/3/10
 * Time: 17:29
 */
class ZhiyuanService
{
    public static function get_data_cache1($user_id,$province_id)
    {
        $enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
        /*//2025年11月12日去除2024，改成2025
        $year = date('Y',strtotime("-1 year"));*/
        $year = date('Y');
        $member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
        $score_min = $member['cj_score']-50;
        $score_max = $member['cj_score']+50;
        if(empty($member['cj_rank'])){
            return [0=>'500',1=>'请先创建成绩'];
        }
        /*//2025年11月12日去除2024，改成2025
        $type = $member['cj_subject_mode_title_2024'];*/
        $type = $member['cj_subject_mode_title'];

        //最新一年院校数据
        $list = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('lowest_rank','>',0)->whereBetween('lowest_score', [$score_min,$score_max])->field('id,school_uuid,college_name,cover_image,school_type as school_xingzhi,province,school_in_city as city,course_selection_name as subject_group,lowest_score as score_min,lowest_rank as weici_min,admission_batch')->order('id asc')->select();
        $school_uuids = array_column($list,'school_uuid');

        // 去除院校重复（佩佩加）
        $uniqueList = [];
        foreach ($list as $item) {
            $key = $item['school_uuid'] . '_' . $item['subject_group'];
            // 如果这个组合还没有出现过，或者当前记录的分数更高，则保留
            if (!isset($uniqueList[$key]) || $item['score_min'] > $uniqueList[$key]['score_min']) {
                $uniqueList[$key] = $item;
            }
        }
        // 重新索引数组
        $list = array_values($uniqueList);


        $school_list = Db::name("school")->field('school_uuid,id,school_suoshu,college_code,school_type,province')->where('school_uuid','in',$school_uuids)->select();
        $school_ids = array_column($school_list,'id');
        $school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
        $school_id_ed = array_column($school_list,'id','school_uuid');
        $school_type_ed = array_column($school_list,'school_type','school_uuid');
        $school_code_ed = array_column($school_list,'college_code','school_uuid');
        $province_ed = array_column($school_list,'province','school_uuid');
        $school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids)->field('d.school_id,t.title')->select();
        $school_tese_new = [];
        foreach($school_tese as $kt=>$vt){
            $school_tese_new[$vt['school_id']][] = $vt['title'];

        }
        $school_type_arr = Db::name('school_type')->column('id,title');
        $suoshu_list = SchoolModel::getSuoshuList();

        $year1 = date('Y',strtotime("-1 year"));
        $year2 = date('Y',strtotime("-2 year"));

        //获取去年专业数据
        $score_min1 = $score_min-80;
        $score_max1 = $score_max+80;
        //$major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //）
        //查询最新一年的招生计划
        $major_list = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year)->where('type',$type)->where('school_uuid','in',$school_uuids)->field('school_uuid,enrollment_numbers as plan_nums,college_major_name as major_name,college_major_code as  major_code,batch_name,special_group_name as subject_group,year')->order('id asc')->select();

        $major_list_new = [];
        foreach($major_list as $km=>$vm){
            $dengxiao_weicha = '-';
            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['score_min'] = '-';
            $vm['weici_min'] = '-';
            $vm['linecha'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new[$vm['school_uuid'].$vm['subject_group']][] = $vm;
        }

        /*$major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group,year')->order('id asc')->select();

        $major_list_new = [];
        foreach($major_list as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            //$major_list_new[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
            $major_list_new[$vm['school_uuid'].$vm['subject_group']][] = $vm;
        }*/

        //获取23年专业数据
        //$major_list_23 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        /*$major_list_23 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group,year')->order('id asc')->select();
    //	dump(($major_list));die;
        $major_list_new_23 = [];
        foreach($major_list_23 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new_23[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
        }*/
        //获取22年专业数据
        //$major_list_22 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        /*$major_list_22 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group,year')->order('id asc')->select();
    //	dump(($major_list));die;
        $major_list_new_22 = [];
        foreach($major_list_22 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new_22[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
        }*/

        if(!empty($list)){
            foreach($list as $k=>$v){
                $school_suoshu = !empty($school_suoshu_ed[$v['school_uuid']])?$school_suoshu_ed[$v['school_uuid']]:'';
                $school_id = !empty($school_id_ed[$v['school_uuid']])?$school_id_ed[$v['school_uuid']]:'';
                $school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
                $school_type = !empty($school_type_ed[$v['school_uuid']])?$school_type_ed[$v['school_uuid']]:'';
                $school_type_title = !empty($school_type_arr[$school_type])?$school_type_arr[$school_type]:'';
                $school_code = !empty($school_code_ed[$v['school_uuid']])?$school_code_ed[$v['school_uuid']]:'';
                $province = !empty($province_ed[$v['school_uuid']])?$province_ed[$v['school_uuid']]:'';

                if(empty($member['cj_rank'])){
                    $dengxiao_weicha = '-';
                }else{
                    if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                        $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                    }else{
                        $dengxiao_weicha = '-';
                    }
                }
                $list[$k]['school_code'] = $school_code;
                $list[$k]['school_type'] = $school_type_title;
                $list[$k]['school_suoshu'] = !empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'';
                $list[$k]['school_tese'] = $school_tese;
                $list[$k]['dengxiao_weicha'] = $dengxiao_weicha;
                $list[$k]['linecha'] = '-';
                $list[$k]['province'] = $province;


                $v['subject_group'] = filter_subject_group($v['subject_group']);
                if(empty($major_list_new[$v['school_uuid'].$v['subject_group']])){
                    unset($list[$k]);
                }else{
                    if(!empty($major_list_new[$v['school_uuid'].$v['subject_group']])){
                        $list[$k]['major_list'] = array_unique_two($major_list_new[$v['school_uuid'].$v['subject_group']]);//咕咕数据有重复的需要去重
                    }else{
                        $list[$k]['major_list'] = [];
                    }
                }
            }

        }
        return [0=>'200',1=>$list];
    }
    public static function get_data_cache($user_id,$province_id)
    {
        $enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
        /*//2025年11月12日去除2024，改成2025
        $year = date('Y',strtotime("-1 year"));*/
        $year = date('Y');
        $member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
        $score_min = $member['cj_score']-50;
        $score_max = $member['cj_score']+50;
        if(empty($member['cj_rank'])){
            return [0=>'500',1=>'请先创建成绩'];
        }
        /*//2025年11月12日去除2024，改成2025
        $type = $member['cj_subject_mode_title_2024'];*/
        $type = $member['cj_subject_mode_title'];

        //最新一年院校数据
        $list = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('lowest_rank','>',0)->whereBetween('lowest_score', [$score_min,$score_max])->field('id,school_uuid,college_name,cover_image,school_type as school_xingzhi,province,school_in_city as city,course_selection_name as subject_group,lowest_score as score_min,lowest_rank as weici_min,admission_batch')->order('id asc')->select();
        $school_uuids = array_column($list,'school_uuid');

        // 去除院校重复（佩佩加）
        $uniqueList = [];
        foreach ($list as $item) {
            $key = $item['school_uuid'] . '_' . $item['subject_group'];

            // 如果这个组合还没有出现过，或者当前记录的分数更高，则保留
            if (!isset($uniqueList[$key]) || $item['score_min'] > $uniqueList[$key]['score_min']) {
                $uniqueList[$key] = $item;
            }
        }
        // 重新索引数组
        $list = array_values($uniqueList);


        $school_list = Db::name("school")->field('school_uuid,id,school_suoshu,college_code,school_type,province')->where('school_uuid','in',$school_uuids)->select();
        $school_ids = array_column($school_list,'id');
        $school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
        $school_id_ed = array_column($school_list,'id','school_uuid');
        $school_type_ed = array_column($school_list,'school_type','school_uuid');
        $school_code_ed = array_column($school_list,'college_code','school_uuid');
        $province_ed = array_column($school_list,'province','school_uuid');
        $school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids)->field('d.school_id,t.title')->select();
        $school_tese_new = [];
        foreach($school_tese as $kt=>$vt){
            $school_tese_new[$vt['school_id']][] = $vt['title'];

        }
        $school_type_arr = Db::name('school_type')->column('id,title');
        $suoshu_list = SchoolModel::getSuoshuList();

        $year1 = date('Y',strtotime("-1 year"));
        $year2 = date('Y',strtotime("-2 year"));

        //获取去年专业数据
        $score_min1 = $score_min-80;
        $score_max1 = $score_max+80;
        //$major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //）
        $major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group,year')->order('id asc')->select();

        $major_list_new = [];
        foreach($major_list as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            //$major_list_new[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
            $major_list_new[$vm['school_uuid'].$vm['subject_group']][] = $vm;
        }

        //获取23年专业数据
        //$major_list_23 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        $major_list_23 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group,year')->order('id asc')->select();
        //	dump(($major_list));die;
        $major_list_new_23 = [];
        foreach($major_list_23 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new_23[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
        }
        //获取22年专业数据
        //$major_list_22 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        $major_list_22 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group,year')->order('id asc')->select();
        //	dump(($major_list));die;
        $major_list_new_22 = [];
        foreach($major_list_22 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new_22[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
        }

        if(!empty($list)){
            foreach($list as $k=>$v){
                $school_suoshu = !empty($school_suoshu_ed[$v['school_uuid']])?$school_suoshu_ed[$v['school_uuid']]:'';
                $school_id = !empty($school_id_ed[$v['school_uuid']])?$school_id_ed[$v['school_uuid']]:'';
                $school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
                $school_type = !empty($school_type_ed[$v['school_uuid']])?$school_type_ed[$v['school_uuid']]:'';
                $school_type_title = !empty($school_type_arr[$school_type])?$school_type_arr[$school_type]:'';
                $school_code = !empty($school_code_ed[$v['school_uuid']])?$school_code_ed[$v['school_uuid']]:'';
                $province = !empty($province_ed[$v['school_uuid']])?$province_ed[$v['school_uuid']]:'';

                if(empty($member['cj_rank'])){
                    $dengxiao_weicha = '-';
                }else{
                    if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                        $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                    }else{
                        $dengxiao_weicha = '-';
                    }
                }
                $list[$k]['school_code'] = $school_code;
                $list[$k]['school_type'] = $school_type_title;
                $list[$k]['school_suoshu'] = !empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'';
                $list[$k]['school_tese'] = $school_tese;
                $list[$k]['dengxiao_weicha'] = $dengxiao_weicha;
                $list[$k]['linecha'] = '-';
                $list[$k]['province'] = $province;

                //匹配去年的专业数据
                /*$v['subject_group'] = filter_subject_group($v['subject_group']);
                if(!empty($major_list_new[$v['school_uuid'].$v['subject_group'].$v['admission_batch']])){
                    $list[$k]['major_list'] = array_unique_two($major_list_new[$v['school_uuid'].$v['subject_group'].$v['admission_batch']]);//咕咕数据有重复的需要去重
                }else{
                    unset($list[$k]);
                }*/
                $v['subject_group'] = filter_subject_group($v['subject_group']);
                if(empty($major_list_new[$v['school_uuid'].$v['subject_group']]) && empty($major_list_new_23[$v['school_uuid'].$v['subject_group'].$v['admission_batch']]) && empty($major_list_new_22[$v['school_uuid'].$v['subject_group'].$v['admission_batch']])){
                    unset($list[$k]);
                }else{
                    if(!empty($major_list_new[$v['school_uuid'].$v['subject_group']])){
                        $list[$k]['major_list'] = array_unique_two($major_list_new[$v['school_uuid'].$v['subject_group']]);//咕咕数据有重复的需要去重
                    }else{
                        if(!empty($major_list_new_23[$v['school_uuid'].$v['subject_group'].$v['admission_batch']])){
                            $list[$k]['major_list'] = array_unique_two($major_list_new_23[$v['school_uuid'].$v['subject_group'].$v['admission_batch']]);//咕咕数据有重复的需要去重
                        }else{
                            $list[$k]['major_list'] = [];
                        }
                    }

                }
            }

        }
        return [0=>'200',1=>$list];
    }
    public static function get_data_cache2($user_id,$province_id)
    {
        $enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
        $year = date('Y',strtotime("-1 year"));
        $member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
        $score_min = $member['cj_score']-50;
        $score_max = $member['cj_score']+50;
        if(empty($member['cj_rank'])){
            return [0=>'500',1=>'请先创建成绩'];
        }
        $type = $member['cj_subject_mode_title_2024'];

        //去年院校数据
        $list = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('lowest_rank','>',0)->whereBetween('lowest_score', [$score_min,$score_max])->field('id,school_uuid,college_name,cover_image,school_type as school_xingzhi,province,school_in_city as city,course_selection_name as subject_group,lowest_score as score_min,lowest_rank as weici_min,admission_batch')->order('id asc')->select();
        $school_uuids = array_column($list,'school_uuid');

        $school_list = Db::name("school")->field('school_uuid,id,school_suoshu,college_code,school_type,province')->where('school_uuid','in',$school_uuids)->select();
        $school_ids = array_column($school_list,'id');
        $school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
        $school_id_ed = array_column($school_list,'id','school_uuid');
        $school_type_ed = array_column($school_list,'school_type','school_uuid');
        $school_code_ed = array_column($school_list,'college_code','school_uuid');
        $province_ed = array_column($school_list,'province','school_uuid');
        $school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids)->field('d.school_id,t.title')->select();
        $school_tese_new = [];
        foreach($school_tese as $kt=>$vt){
            $school_tese_new[$vt['school_id']][] = $vt['title'];

        }
        $school_type_arr = Db::name('school_type')->column('id,title');
        $suoshu_list = SchoolModel::getSuoshuList();

        $year1 = date('Y',strtotime("-2 year"));
        $year2 = date('Y',strtotime("-3 year"));

        //获取去年专业数据
        $score_min1 = $score_min-80;
        $score_max1 = $score_max+80;
        //$major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        $major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        $major_list_new = [];
        foreach($major_list as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            //$major_list_new[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
            $major_list_new[$vm['school_uuid'].$vm['subject_group']][] = $vm;
        }

        //获取23年专业数据
        //$major_list_23 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        $major_list_23 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //	dump(($major_list));die;
        $major_list_new_23 = [];
        foreach($major_list_23 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new_23[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
        }
        //获取22年专业数据
        //$major_list_22 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        $major_list_22 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //	dump(($major_list));die;
        $major_list_new_22 = [];
        foreach($major_list_22 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new_22[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
        }

        if(!empty($list)){
            foreach($list as $k=>$v){
                $school_suoshu = !empty($school_suoshu_ed[$v['school_uuid']])?$school_suoshu_ed[$v['school_uuid']]:'';
                $school_id = !empty($school_id_ed[$v['school_uuid']])?$school_id_ed[$v['school_uuid']]:'';
                $school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
                $school_type = !empty($school_type_ed[$v['school_uuid']])?$school_type_ed[$v['school_uuid']]:'';
                $school_type_title = !empty($school_type_arr[$school_type])?$school_type_arr[$school_type]:'';
                $school_code = !empty($school_code_ed[$v['school_uuid']])?$school_code_ed[$v['school_uuid']]:'';
                $province = !empty($province_ed[$v['school_uuid']])?$province_ed[$v['school_uuid']]:'';

                if(empty($member['cj_rank'])){
                    $dengxiao_weicha = '-';
                }else{
                    if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                        $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                    }else{
                        $dengxiao_weicha = '-';
                    }
                }
                $list[$k]['school_code'] = $school_code;
                $list[$k]['school_type'] = $school_type_title;
                $list[$k]['school_suoshu'] = !empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'';
                $list[$k]['school_tese'] = $school_tese;
                $list[$k]['dengxiao_weicha'] = $dengxiao_weicha;
                $list[$k]['linecha'] = '-';
                $list[$k]['province'] = $province;

                //匹配去年的专业数据
                /*$v['subject_group'] = filter_subject_group($v['subject_group']);
                if(!empty($major_list_new[$v['school_uuid'].$v['subject_group'].$v['admission_batch']])){
                    $list[$k]['major_list'] = array_unique_two($major_list_new[$v['school_uuid'].$v['subject_group'].$v['admission_batch']]);//咕咕数据有重复的需要去重
                }else{
                    unset($list[$k]);
                }*/
                $v['subject_group'] = filter_subject_group($v['subject_group']);
                if(empty($major_list_new[$v['school_uuid'].$v['subject_group']]) && empty($major_list_new_23[$v['school_uuid'].$v['subject_group'].$v['admission_batch']]) && empty($major_list_new_22[$v['school_uuid'].$v['subject_group'].$v['admission_batch']])){
                    unset($list[$k]);
                }else{
                    if(!empty($major_list_new[$v['school_uuid'].$v['subject_group']])){
                        $list[$k]['major_list'] = array_unique_two($major_list_new[$v['school_uuid'].$v['subject_group']]);//咕咕数据有重复的需要去重
                    }else{
                        $list[$k]['major_list'] = [];
                    }

                }
            }

        }
        return [0=>'200',1=>$list];
    }

}